# encoding  :  utf-8 _*_
# @author   :  朱清闯
# @software :  PyCharm
# time      :  2022/3/22 9:33
import urllib.parse
import urllib.request


def send_message_by_huyiwuxian(mobile, message_code):
    # 接口地址
    url = 'http://106.ihuyi.com/webservice/sms.php?method=Submit'

    # 定义请求的数据
    values = {
        'account': 'C85572129',
        'password': '712aaa553ea390dfb7279633371f25e4',
        'mobile': mobile,
        'content': f'来自题库系统，您的验证码为：{message_code}，如非本人操作，请忽略本短信！',
        'format': 'json',
    }
    # 将数据进行编码
    data = urllib.parse.urlencode(values).encode(encoding='UTF8')
    # 发起请求
    req = urllib.request.Request(url, data)
    response = urllib.request.urlopen(req)
    res = response.read()
    # 打印结果
    print(values['content'])
    return res.decode("utf8")

